/*
 * IntersectionHClass.java
 *
 * Created on October 9, 2007, 1:36 PM
 *
 */
package OLDSTUFF;

import HierarchyPackage.*;
import java.util.Arrays;

/**
 * Classification class belonging to a IntersectionHierarchy.
 * This class can not be instantiated - only returned from a IntersectionHierarchy
 * (i.e. only a IntersectionHierarchy can instantiate it).
 * @author Martin Haulrich
 */
public final class IntersectionHClass implements HClass {

    /**
     * The classes that makes up this intersecting class
     */
    final HClass[] classes;

    /**
     * The IntersectionHierarchyTT this class belongs to.
     */
    final IntersectionHierarchy hier;

    /** Constructor
     * @param hier The IntersectionHierarchyTT this class belongs to.
     * @param classes The classes thats makes up this intersection classification
     */
    public IntersectionHClass(IntersectionHierarchy hier, HClass[] classes) {
        this.hier = hier;
        // Make sure that the right information is saved in case HClass[] is overwritten

        // JDK 1.6
        this.classes = Arrays.copyOf(classes, classes.length);


    // JDK 1.5
    //this.classes = new HClass[classes.length];
    //System.arraycopy(classes,0,this.classes,0,classes.length);


    }

    @Override
    public String getName() {
        return hier.getName(this);
    }

    /**
     * Returns the classes that identifies this class
     * @return the classes that identifies this class.
     */
    public HClass[] getID() {
        return classes;
    }

    @Override
    public Hierarchy belongsTo() {
        return hier;
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(classes);
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof IntersectionHClass) {
            return Arrays.equals(((IntersectionHClass) o).getID(), classes);
        }
        return false;
    }
}
